<template>
  <el-dialog :visible="visible" title="添加分组" width="30%" @close="close">
    <el-form label-width="80px">
      <el-form-item label="分组名称">
        <el-input v-model="dict.dictname" placeholder="请输入分组名称,如产品类别"></el-input>
      </el-form-item>

      <div class="btn">
        <el-button type="primary" @click="save">保存</el-button>
        <el-button type="info" @click="close">取消</el-button>
      </div>

    </el-form>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      dict: {
        dictname: "",
        parentid: "1",
        euid: ""
      },
      user: {}
    }
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    init() {
      let tmp = this.user = this.$session.getUser();
      this.dict = {
        dictname: "",
        parentid: "1",
        euid: tmp.euid
      };
    },
    close() {
      this.$emit("update:visible", false);
    },
    save() {
      this.$api.saveDict(this.dict)
        .then(res => {
          if (res.code === 200) {
            this.$message({
              message: '保存成功',
              type: 'success'
            });
            this.close();
            //刷新数据
            this.$emit("refreshData");
          }
        })
    }
  }
}
</script>

<style scoped>
.btn {
  text-align: center;
  margin-top: 30px;
}

.btn button {
  margin-left: 30px;
}

.el-input {
  width: 80%;
  margin-left: 20px;
}
</style>
